// NewMapDlg.cpp : implementation file
//

#include "stdafx.h"
#include "NewMapDlg.h"

//////////////////////////////////////////////////////////////////////////

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

//////////////////////////////////////////////////////////////////////////

// NewMapDlg dialog

IMPLEMENT_DYNAMIC(NewMapDlg, CDialog)

NewMapDlg::NewMapDlg(CWnd* pParent) : CDialog(NewMapDlg::IDD, pParent)
{
	mMapNameCtrl = _T("unname");
	mTerrainWidthCtrl = 0;
	mTerrainHeightCtrl = 0;
	mGridStrideCtrl = 0;
	mGridSizeCtrl = 1;
	mAlphaStrideCtrl = 0;
}

NewMapDlg::~NewMapDlg()
{
}

void NewMapDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	DDX_Text(pDX, IDC_NEWMAP_MAP_NAME, mMapNameCtrl);
	DDX_CBIndex(pDX, IDC_NEWMAP_TERRAIN_WIDTH, mTerrainWidthCtrl);
	DDX_CBIndex(pDX, IDC_NEWMAP_TERRAIN_HEIGHT, mTerrainHeightCtrl);
	DDX_CBIndex(pDX, IDC_NEWMAP_GRID_STRIDE, mGridStrideCtrl);
	DDX_CBIndex(pDX, IDC_NEWMAP_GRID_SIZE, mGridSizeCtrl);
	DDX_CBIndex(pDX, IDC_NEWMAP_ALPHA_STRIDE, mAlphaStrideCtrl);
}

//////////////////////////////////////////////////////////////////////////

BEGIN_MESSAGE_MAP(NewMapDlg, CDialog)
	ON_CBN_SELCHANGE(IDC_NEWMAP_TERRAIN_WIDTH, &NewMapDlg::OnCbnSelchangeSetting)
	ON_CBN_SELCHANGE(IDC_NEWMAP_TERRAIN_HEIGHT, &NewMapDlg::OnCbnSelchangeSetting)
	ON_CBN_SELCHANGE(IDC_NEWMAP_GRID_STRIDE, &NewMapDlg::OnCbnSelchangeSetting)
	ON_CBN_SELCHANGE(IDC_NEWMAP_GRID_SIZE, &NewMapDlg::OnCbnSelchangeSetting)
	ON_CBN_SELCHANGE(IDC_NEWMAP_ALPHA_STRIDE, &NewMapDlg::OnCbnSelchangeSetting)
	ON_WM_CREATE()
END_MESSAGE_MAP()

int NewMapDlg::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
	if (CDialog::OnCreate(lpCreateStruct) == -1) return -1;
	SetFont(CFont::FromHandle((HFONT) GetStockObject(DEFAULT_GUI_FONT)));
	return 0;
}

// NewMapDlg message handlers
void NewMapDlg::OnCbnSelchangeSetting()
{
	UpdateData();

	unsigned int terrain_width = 32;
	switch (mTerrainWidthCtrl)
	{
	case 0: 
		terrain_width = 32; 
		break;
	case 1: 
		terrain_width = 64; 
		break;
	case 2: 
		terrain_width = 128; 
		break;
	case 3: 
		terrain_width = 256; 
		break;
	case 4: 
		terrain_width = 512; 
		break;
	case 5: 
		terrain_width = 1024; 
		break;
	}

	unsigned int terrain_height = 32;
	switch (mTerrainHeightCtrl)
	{
	case 0: 
		terrain_height = 32; 
		break;
	case 1: 
		terrain_height = 64; 
		break;
	case 2: 
		terrain_height = 128; 
		break;
	case 3: 
		terrain_height = 256; 
		break;
	case 4: 
		terrain_height = 512; 
		break;
	case 5: 
		terrain_height = 1024; 
		break;
	}

	unsigned int grid_stride = 16;
	switch (mGridStrideCtrl)
	{
	case 0: 
		grid_stride = 16; 
		break;
	case 1: 
		grid_stride = 32; 
		break;
	case 2: 
		grid_stride = 64; 
		break;
	case 3: 
		grid_stride = 128; 
		break;
	case 4: 
		grid_stride = 256; 
		break;
	}

	float grid_size = 1.0;
	switch (mGridSizeCtrl)
	{
	case 0: 
		grid_size = 0.5; 
		break;
	case 1: 
		grid_size = 1.0; 
		break;
	case 2: 
		grid_size = 2.0; 
		break;
	case 3: 
		grid_size = 4.0; 
		break;
	}

	unsigned int alpha_stride = 16;
	switch (mAlphaStrideCtrl)
	{
	case 0: 
		alpha_stride = 16; 
		break;
	case 1: 
		alpha_stride = 32; 
		break;
	case 2: 
		alpha_stride = 64; 
		break;
	}
	
	CString text;
	text.Format("%f",terrain_width*grid_stride*grid_size );
	GetDlgItem(IDC_STATIC_TERRAIN_WIDTH)->SetWindowText(text);

	text.Format("%f",terrain_height*grid_stride*grid_size );
	GetDlgItem(IDC_STATIC_TERRAIN_HEIGHT)->SetWindowText(text);

	text.Format("%f",grid_stride*grid_size );
	GetDlgItem(IDC_STATIC_BLOCK_SIZE)->SetWindowText(text);

	text.Format("%u",terrain_width*terrain_height*grid_stride*grid_stride*2 );
	GetDlgItem(IDC_STATIC_HEIGHTMAP_SIZE)->SetWindowText(text);

	text.Format("%u",terrain_width*terrain_height*grid_stride*grid_stride*2 );
	GetDlgItem(IDC_STATIC_MAP_SIZE)->SetWindowText(text);
}
